// 商品分类
import api from '@/tools/api.js'
import promise from '@/tools/promise'
// import { SUCCESS_STATUS } from '@/config/status'
import {
  BILLS_LIST
} from '@/store/mutation-types'

const state = {
  pageData: {
    total: 1,
    per_page: 15,
    current_page: 1,
    last_page: 1
  },
  billsList: []
}

// mutations
const mutations = {
  [BILLS_LIST] (state, res) {
    state.billsList = res.data
    state.pageData.total = Number(res.total)
    state.pageData.per_page = Number(res.per_page)
    state.pageData.current_page = Number(res.current_page)
    state.pageData.last_page = Number(res.last_page)
  }
}

// actions
const actions = {
  // 获取账单列表
  async billsList ({ commit }, payload) {
    let listRes = await api('servergoods/goods/Goods/allAccountBookList', payload)
    commit(BILLS_LIST, listRes.res)
  },
  // 结算账单
  async signSettlement ({ commit }, payload) {
    let res = await api('servergoods/goods/Goods/signSettlement', payload)
    return promise(res)
  },
  // 添加账单
  async accountAdd ({ commit }, payload) {
    let addRes = await api('servergoods/goods/Goods/addAccountBook', payload)
    return promise(addRes)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
